﻿using System;
using System.Web;
using Microsoft.Practices.Unity;
using TSharp.Core.Osgi;
using TSharp.Core.Osgi.Internal;

namespace TSharp.Core.Unity
{
	partial class UnityServiceSituation
	{
        internal IUnityContainer CreateRequestContainer()
		{
			log.Debug("创建 Request");

			IUnityContainer container =GetOrCreateSessionWrapper().unity.CreateChildContainer();

			UnitySection.Configure(container, CONFIG_CONTAINER_NAME_REQUEST);

			Configure(ServiceManager.RequsetMap, container);

			return container;
		}


        private UnityLocatorWrapper GetOrCreateRequestWrapper()
        {
            return AopContext.GetContext().Request.GetOrAdd(CACHEKEY_REQUSET_CONTAINER, k =>
                new UnityLocatorWrapper(CreateRequestContainer(), Level.REQUSET)) as UnityLocatorWrapper;
        }
        
	}
}